﻿@using System.Globalization
@model AutoPartsSearch.Web.Areas.Administration.Models.LocalizeTypes.IndexModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Administration/Views/_Layout.cshtml";
}
@section menu
    {
        @Html.Partial("_contextMenu")
    }
<div class="griffin">
    <h2>@CultureInfo.CurrentUICulture.DisplayName</h2>
    @using (Html.BeginForm("CreateLanguage", "LocalizeTypes"))
    {
        @Html.ValidationSummary(true)
        <div style="float: right">
            Change language:
            @Html.DropDownList("changeLanguage", Model.CultureItems, "", CultureInfo.CurrentUICulture.Name)
        </div>
        <div>
            Create language (should be a lang code like "sv-se")
            <input type="text" name="lang" />
            <input type="submit" value="Create" />
        </div>
        <div>
            <label>@Html.CheckBoxFor(model => model.ShowMetadata) Show metadata</label>
        </div>
    }
    <table>
        <tr>
            <th>
                Typename
            </th>
            <th>
                TextName
            </th>
            <th>
                TranslatedText
            </th>
            <th>
            </th>
        </tr>
        @foreach (var item in Model.Prompts)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.ModelName)
                    <span style="color: #cccccc">@Html.DisplayFor(modelItem => item.Namespace)</span>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.TextName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.TranslatedText)
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new {id = item.TextKey})
                    @Html.ActionLink("Delete", "Delete", new {id = item.TextKey})
                    @if (item.ModelName != "CommonPrompts")
                    {
                        @Html.ActionLink("Make common", "MakeCommon", new {id = item.TextKey}, new {title = "Use this phrase for all properties with the same name that haven't got a translation."})
                    }
                </td>
            </tr>
        }
        
        <tfoot>
            <tr>
                <td colspan="4">
                    @if (ViewBag.PageNumber > 1)
                    {
                        @Html.ActionLink("<< ", "Index", new {pageNumber = ViewBag.PageNumber - 1})
                    }
                    @Html.ActionLink(((int)ViewBag.PageNumber).ToString(), "Index", new { pageNumber = ViewBag.PageNumber })
                    @Html.ActionLink(" >>", "Index", new {pageNumber = ViewBag.PageNumber + 1})
                </td>
            </tr>
        </tfoot>
    </table>
    <script type="text/javascript">

        $(function() {
            $('#ShowMetadata').click(function() {
                var show = this.checked ? 1 : 0;
                setCookie('ShowMetadata', show, 365);
                window.location.reload();
            });
            $('#changeLanguage').change(function() {
                window.location = '@Url.Action("Index")?lang=' + $('#changeLanguage').val();
            });

        });

    </script>
</div>
